#include "ChessProcessor.h"
#include "preprocess.h"
#include "chessdatabase.h"
#include "FeatureExtractor.h"

// 打印函数实现
void printChessPiece(const ChessDatabase::ChessPiece& piece) {
    std::cout << std::fixed << std::setprecision(2); // 设置浮点数精度
    
    std::cout << "ChessPiece #" << piece.num << ":\n";
    std::cout << "  Position: (" << piece.x << ", " << piece.y << ")\n";
    std::cout << "  Color: " << piece.color << "\n";
    std::cout << "  Type: " << piece.type << "\n";
    
    // 打印Hu矩
    std::cout << "  Hu Moments: [ ";
    for (size_t i = 0; i < piece.huMoments.size(); ++i) {
        std::cout << piece.huMoments[i] << " ";
    }
    std::cout << "]\n";
    
    // 打印几何特征
    std::cout << "  Area: " << piece.area << "\n";
    std::cout << "  Perimeter: " << piece.perimeter << "\n";
    std::cout << "  Aspect Ratio: " << piece.aspectRatio << "\n";
    
    // 打印投影直方图
    std::cout << "  Projection Histogram: [ ";
    for (size_t i = 0; i < piece.projHist.size(); ++i) {
        std::cout << piece.projHist[i] << " ";
    }
    std::cout << "]\n";
    
    // 打印区域密度
    std::cout << "  Zone Density: [ ";
    for (size_t i = 0; i < piece.zoneDensity.size(); ++i) {
        std::cout << piece.zoneDensity[i] << " ";
    }
    std::cout << "]\n";
}

int main() {
    // 设置根目录路径（根据你的实际路径修改）
    std::string rootDirectory = "/mnt/hgfs/aic_jeff/final_project/3.棋局获取显示/3.1棋子检测识别/棋子素材";
    // 开始处理所有棋子
   processChessPieces(rootDirectory);
   
  // std::string testImagePath = "/mnt/hgfs/aic_jeff/final_project/3.棋局获取显示/3.1棋子检测识别/Project1/Project1/红车.jpg"; 
  // testChessRecognition(testImagePath);
	
	
	//ChessDatabase db("test.db");
	/*
	cv::Mat croppedImage;
	
	try {
        ImageProcessor processor("/mnt/hgfs/aic_jeff/final_project/3.棋局获取显示/3.1棋子检测识别/Project1/Project1/黑车.png");
        
        if (processor.processImage()) {
            cv::imshow("原始图像", processor.getResultImage());
            cv::imshow("裁剪结果", processor.getCroppedImage());
			croppedImage=processor.getCroppedImage();
            cv::waitKey(0);
        }
    } catch (const std::exception& e) {
        std::cerr << "错误: " << e.what() << std::endl;
        //return -1;
    }
	ChessDatabase::ChessPiece piece=extractChessPieceFeatures(
	croppedImage,
	1,
	2,
	"pawn"
	);
	printChessPiece(piece);
	
	//db.addChessPiece(piece);
*/
   
    return 0;
}